﻿Imports System.Data
Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types
Public Class EditBS

    Dim objConn As OracleConnection
    Dim dtadapter As OracleDataAdapter
    Dim objCmd As New OracleCommand
    Dim da As OracleDataAdapter
    Dim cb As OracleCommandBuilder
    Dim ds As DataSet
    Dim Udone As New Err
    Dim Done As New Done
    Dim infor As New infor

    Private Sub BT1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BT1.Click
        Me.Close()
    End Sub

    Private Sub EditBS_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dellbl.Visible = False
        Delno.Visible = False
        DelOk.Visible = False
        editno.Visible = False
        editok.Visible = False
        Editlbl.Visible = False
        Dellbl1.Visible = False
        Delno1.Visible = False
        DelOk1.Visible = False
        editno1.Visible = False
        editok1.Visible = False
        Editlbl1.Visible = False
        txtboxEnableF()
        textbox1.Enabled = True
        Textbox5.Enabled = True
        DataSC()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Then
            infor.ShowDialog()
        Else
            TextBox2.Text = ""
            TextBox3.Text = ""
            TextBox4.Text = ""
            TextBox2.Enabled = True
            TextBox3.Enabled = True
            TextBox4.Enabled = True
            Try
                Dim sql As String = "select * from MANUFACTUR where MANUFAC_ID = '" + TextBox1.Text + "'"
                dtadapter = New OracleDataAdapter(sql, objConn)
                Dim dt As New DataTable
                dtadapter.Fill(dt)

                TextBox2.Text = dt.Rows(0)("MANUFAC_NAME")
                TextBox3.Text = dt.Rows(0)("ADDRESS")
                TextBox4.Text = dt.Rows(0)("TEL_NO")
            Catch ex As Exception
                Udone.ShowDialog()
                TextBox2.Enabled = False
                TextBox3.Enabled = False
                TextBox4.Enabled = False
            End Try
        End If
    End Sub

    Private Sub BT4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BT4.Click
        If textbox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
            infor.ShowDialog()
        Else
            Editlbl1.Visible = True
            editno1.Visible = True
            editok1.Visible = True
            BT2.Enabled = False
            BT3.Enabled = False
            BT4.Enabled = False
            BT5.Enabled = False
            Button1.Enabled = False
            Button2.Enabled = False
            txtboxEnableF()
        End If
    End Sub

    Private Sub BT5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BT5.Click
        If textbox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
            infor.ShowDialog()
        Else
            Dellbl1.Visible = True
            Delno1.Visible = True
            DelOk1.Visible = True
            BT2.Enabled = False
            BT3.Enabled = False
            BT4.Enabled = False
            BT5.Enabled = False
            Button1.Enabled = False
            Button2.Enabled = False
            txtboxEnableF()
        End If
    End Sub

    Private Sub editok1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles editok1.Click
        Editlbl1.Visible = False
        editno1.Visible = False
        editok1.Visible = False
        BT2.Enabled = True
        BT3.Enabled = True
        BT4.Enabled = True
        BT5.Enabled = True
        Button1.Enabled = True
        Button2.Enabled = True
        TextBox1.Enabled = True
        TextBox2.Enabled = True
        TextBox3.Enabled = True
        TextBox4.Enabled = True
        TextBox5.Enabled = True
        TextBox6.Enabled = True
        TextBox7.Enabled = True
        TextBox8.Enabled = True

        Try
            If TextBox4.Text = "" Then
                TextBox4.Text = "None"
            End If
            Dim sql As String = "Update MANUFACTUR SET MANUFAC_ID = '" + TextBox1.Text + "',MANUFAC_NAME = '" + TextBox2.Text _
                                + "',ADDRESS = '" + TextBox3.Text + "',TEL_NO = '" + TextBox4.Text + "' WHERE MANUFAC_ID = '" + TextBox1.Text + "'"
            objCmd = New OracleCommand
            With objCmd
                .Connection = objConn
                .CommandText = sql
                .CommandType = CommandType.Text
            End With
            Try
                objCmd.ExecuteNonQuery()
                Done.ShowDialog()
            Catch ex As Exception
                Udone.ShowDialog()
            End Try
        Catch ex As Exception
            Udone.ShowDialog()
        Finally
            objConn.Dispose()
            DataSC()
        End Try
    End Sub

    Private Sub editno1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles editno1.Click
        Editlbl1.Visible = False
        editno1.Visible = False
        editok1.Visible = False
        BT2.Enabled = True
        BT3.Enabled = True
        BT4.Enabled = True
        BT5.Enabled = True
        Button1.Enabled = True
        Button2.Enabled = True
        TextBox1.Enabled = True
        TextBox5.Enabled = True
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
    End Sub

    Private Sub DelOk1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DelOk1.Click
        Dellbl1.Visible = False
        Delno1.Visible = False
        DelOk1.Visible = False
        BT2.Enabled = True
        BT3.Enabled = True
        BT4.Enabled = True
        BT5.Enabled = True
        Button1.Enabled = True
        Button2.Enabled = True
        TextBox1.Enabled = True
        TextBox5.Enabled = True

        Try

            Dim sql As String = "DELETE FROM MANUFACTUR WHERE MANUFAC_ID = '" + TextBox1.Text + "'"
            objCmd = New OracleCommand(sql, objConn)
            Try
                objCmd.ExecuteNonQuery()
                Done.ShowDialog()
            Catch ex As Exception
                Udone.ShowDialog()
            End Try
        Catch ex As Exception
            Udone.ShowDialog()
        Finally
            objConn.Dispose()
            DataSC()
        End Try
    End Sub

    Private Sub Delno1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Delno1.Click
        Dellbl1.Visible = False
        Delno1.Visible = False
        DelOk1.Visible = False
        BT2.Enabled = True
        BT3.Enabled = True
        BT4.Enabled = True
        BT5.Enabled = True
        Button1.Enabled = True
        Button2.Enabled = True
        TextBox1.Enabled = True
        TextBox5.Enabled = True
    End Sub

    Private Sub BT2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BT2.Click
        If Textbox5.Text = "" Or TextBox6.Text = "" Or TextBox7.Text = "" Then
            infor.ShowDialog()
        Else
            Editlbl.Visible = True
            editno.Visible = True
            editok.Visible = True
            BT2.Enabled = False
            BT3.Enabled = False
            BT4.Enabled = False
            BT5.Enabled = False
            Button1.Enabled = False
            Button2.Enabled = False
            txtboxEnableF()
        End If
    End Sub

    Private Sub BT3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BT3.Click
        If Textbox5.Text = "" Or TextBox6.Text = "" Or TextBox7.Text = "" Then
            infor.ShowDialog()
        Else
            Dellbl.Visible = True
            Delno.Visible = True
            DelOk.Visible = True
            BT2.Enabled = False
            BT3.Enabled = False
            BT4.Enabled = False
            BT5.Enabled = False
            Button1.Enabled = False
            Button2.Enabled = False
            txtboxEnableF()
        End If
    End Sub

    Private Sub editok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles editok.Click
        Editlbl.Visible = False
        editno.Visible = False
        editok.Visible = False
        BT2.Enabled = True
        BT3.Enabled = True
        BT4.Enabled = True
        BT5.Enabled = True
        Button1.Enabled = True
        Button2.Enabled = True
        TextBox1.Enabled = True
        TextBox2.Enabled = True
        TextBox3.Enabled = True
        TextBox4.Enabled = True
        TextBox5.Enabled = True
        TextBox6.Enabled = True
        TextBox7.Enabled = True
        TextBox8.Enabled = True

        Try
            If TextBox8.Text = "" Then
                TextBox8.Text = "None"
            End If
            Dim sql As String = "Update SELLER SET ID_SELLER = '" + TextBox5.Text + "',SELLER_NAME = '" + TextBox6.Text _
                                + "',ADDRESS = '" + TextBox7.Text + "',TEL_NO = '" + TextBox8.Text + "' WHERE ID_SELLER = '" + TextBox5.Text + "'"
            objCmd = New OracleCommand
            With objCmd
                .Connection = objConn
                .CommandText = sql
                .CommandType = CommandType.Text
            End With
            Try
                objCmd.ExecuteNonQuery()
                Done.ShowDialog()
            Catch ex As Exception
                Udone.ShowDialog()
            End Try
        Catch ex As Exception
            Udone.ShowDialog()
        Finally
            objConn.Dispose()
            DataSC()
        End Try
    End Sub

    Private Sub editno_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles editno.Click
        Editlbl.Visible = False
        editno.Visible = False
        editok.Visible = False
        BT2.Enabled = True
        BT3.Enabled = True
        BT4.Enabled = True
        BT5.Enabled = True
        Button1.Enabled = True
        Button2.Enabled = True
        TextBox1.Enabled = True
        TextBox5.Enabled = True
        TextBox5.Text = ""
        TextBox6.Text = ""
        TextBox7.Text = ""
        TextBox8.Text = ""
    End Sub

    Private Sub DelOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DelOk.Click
        Dellbl.Visible = False
        Delno.Visible = False
        DelOk.Visible = False
        BT2.Enabled = True
        BT3.Enabled = True
        BT4.Enabled = True
        BT5.Enabled = True
        Button1.Enabled = True
        Button2.Enabled = True
        TextBox1.Enabled = True
        TextBox5.Enabled = True

        Try
            Dim sql As String = "DELETE FROM SELLER WHERE ID_SELLER = '" + TextBox5.Text + "'"
            objCmd = New OracleCommand(sql, objConn)
            Try
                objCmd.ExecuteNonQuery()
                Done.ShowDialog()
            Catch ex As Exception
                Udone.ShowDialog()
            End Try
        Catch ex As Exception
            Udone.ShowDialog()
        Finally
            objConn.Dispose()
            DataSC()
        End Try
    End Sub

    Private Sub Delno_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Delno.Click
        Dellbl.Visible = False
        Delno.Visible = False
        DelOk.Visible = False
        BT2.Enabled = True
        BT3.Enabled = True
        BT4.Enabled = True
        BT5.Enabled = True
        Button1.Enabled = True
        Button2.Enabled = True
        TextBox1.Enabled = True
        TextBox5.Enabled = True
        TextBox5.Text = ""
        TextBox6.Text = ""
        TextBox7.Text = ""
        TextBox8.Text = ""
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If TextBox5.Text = "" Then
            infor.ShowDialog()
        Else
            TextBox6.Text = ""
            TextBox7.Text = ""
            TextBox8.Text = ""
            TextBox6.Enabled = True
            TextBox7.Enabled = True
            TextBox8.Enabled = True
            Try
                Dim sql As String = "select * from SELLER where ID_SELLER = '" + TextBox5.Text + "'"
                dtadapter = New OracleDataAdapter(sql, objConn)
                Dim dt As New DataTable
                dtadapter.Fill(dt)

                TextBox6.Text = dt.Rows(0)("SELLER_NAME")
                TextBox7.Text = dt.Rows(0)("ADDRESS")
                TextBox8.Text = dt.Rows(0)("TEL_NO")
            Catch ex As Exception
                Udone.ShowDialog()
                TextBox6.Enabled = False
                TextBox7.Enabled = False
                TextBox8.Enabled = False
            End Try
        End If
    End Sub

    Private Sub DataSC()
        Dim strConnString As String
        strConnString = Login.strConn
        objConn = New OracleConnection(strConnString)
        objConn.Open()
        Dim cmd2 As New OracleCommand
        Dim sql1 As String = "select * from MANUFACTUR ORDER BY MANUFAC_ID ASC"
        cmd2 = New OracleCommand(sql1, objConn)
        da = New OracleDataAdapter(cmd2)
        cb = New OracleCommandBuilder(da)
        ds = New DataSet()
        da.Fill(ds, "MANUFACTUR")

        With Me.textbox1
            .DataSource = ds.Tables("MANUFACTUR")
            .DisplayMember = "MANUFAC_ID"
            .ValueMember = "MANUFAC_ID"
        End With

        Dim cmd3 As New OracleCommand
        Dim sql2 As String = "select * from SELLER ORDER BY ID_SELLER ASC"
        cmd3 = New OracleCommand(sql2, objConn)
        da = New OracleDataAdapter(cmd3)
        cb = New OracleCommandBuilder(da)
        ds = New DataSet()
        da.Fill(ds, "SELLER")

        With Me.Textbox5
            .DataSource = ds.Tables("SELLER")
            .DisplayMember = "ID_SELLER"
            .ValueMember = "ID_SELLER"
        End With       
        Textbox5.Text = ""
        TextBox6.Text = ""
        TextBox7.Text = ""
        TextBox8.Text = ""
        TextBox2.Enabled = False
        TextBox3.Enabled = False
        TextBox4.Enabled = False
        textbox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
    End Sub

    Private Sub txtboxEnableF()
        textbox1.Enabled = False
        TextBox2.Enabled = False
        TextBox3.Enabled = False
        TextBox4.Enabled = False
        Textbox5.Enabled = False
        TextBox6.Enabled = False
        TextBox7.Enabled = False
        TextBox8.Enabled = False
    End Sub

End Class